package com.portal.userregistration;

import java.util.ArrayList;
import java.util.List;

import javax.portlet.RenderResponse;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;

import sample.code.listing.controller.AbstractBaseController;
import sample.code.listing.domain.Book;
import com.teachlearnweb.service.vo.BookVO;



/**
 * UserRegistrationController shows the books in the book Catalog.
 * @author asarin
 *
 */
@Controller("userRegistrationController")
@RequestMapping(value = "VIEW")
public class UserRegistrationController extends AbstractBaseController{


	// --maps the incoming portlet request to this method
	@RenderMapping
	public String showRegistrationForm(RenderResponse response) {
		return "userRegistrationForm";
	}

	// -- @ModelAttribute here works as the referenceData method
	@ModelAttribute(value="books")
	public List<Book> getBooks() {
		List<Book> books = new ArrayList<Book>();
		List<BookVO> bookVoList = serviceLocator.getBookService().getBooks();
		System.out.println("bookVoList size.............."+bookVoList.size());
		/*for (int i = 0; i < bookVoList.size(); i++) {
			BeanUtils.copyProperties(bookVoList(i), booksList(i));
		}*/
		
		
		books.add(new Book("AspectJ in Action, Second Edition", "Ramnivas Laddad", Long.valueOf("1933988053")));
		books.add(new Book("ActiveMQ in Action", "Bruce Snyder, Dejan Bosanac, and Rob Davies", Long.valueOf("1933988940")));
		books.add(new Book("Hadoop in Action", "Chuck Lam", Long.valueOf("9781935182191")));
		books.add(new Book("JUnit in Action, Second Edition", "Petar Tahchiev, Felipe Leme, Vincent Massol, and Gary Gregory", Long.valueOf("9781935182023")));
		
		return books;
	}
}
